package top.dancun.easuser.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import top.dancun.common.entity.UserEntity;
import top.dancun.common.entity.UserTokenEntity;
import top.dancun.common.utils.R;
import top.dancun.easuser.service.ShiroService;

import java.util.Set;

@RestController
@RequestMapping("/shiro")
public class shiroController extends AbstractController{
    @Autowired
    ShiroService shiroService;
    @PostMapping("/getUserPermissions")
    public R getUserPermissions(@RequestParam(name = "token") String token){
        UserTokenEntity userTokenEntity = shiroService.queryByToken(token);
        Set<String> permissions = shiroService.getUserPermissions(userTokenEntity.getUserId());
        return R.ok().put("permissions",permissions);
    }

    @PostMapping("/queryByToken")
    public R queryByToken(@RequestParam(name = "token") String token){
        UserTokenEntity userTokenEntity = shiroService.queryByToken(token);
        return R.ok().put("userTokenEntity",userTokenEntity);
    }

    @PostMapping("/queryUser")
    public R queryUser(@RequestParam(name = "token") String token){
        UserTokenEntity userTokenEntity = shiroService.queryByToken(token);
        UserEntity user = shiroService.queryUser(userTokenEntity.getUserId());
        return R.ok().put("user",user);

    }
}
